//
//  MPSettingsManager.m
//  SearchPeople
//
//  Created by YoloMao on 16/5/5.
//
//

#import "MPSettingsManager.h"

static MPSettingsManager *settingsManager = nil;

@implementation MPSettingsManager

+ (MPSettingsManager *)getInstance
{
    if (!settingsManager)
    {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            settingsManager = [[MPSettingsManager alloc]init];
        });
    }
    return settingsManager;
}

- (id)init
{
    self = [super init];
    if (self)
    {
        self.userDefault = [NSUserDefaults standardUserDefaults];
    }
    return self;
}

//正则表达式判断手机号等
- (BOOL)judgePassword:(NSString *)password
{
    NSString *regular = @"^[a-z0-9_-]{6,18}$";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regular];
    BOOL result = [predicate evaluateWithObject:password];
    return result;
}

- (BOOL)isValidateMobile:(NSString *)mobile
{
    // 手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}

- (BOOL)isValidateMail:(NSString *)mail
{
    NSString *mailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", mailRegex];
    return [phoneTest evaluateWithObject:mail];
}

@end
